package cn.itcast.nems.journal.service.impl;

import cn.itcast.nems.journal.service.JournalRenewalOrderRelationshipService;
import cn.itcast.nems.studentrecord.dao.entity.JournalRenewalOrderRelationship;
import cn.itcast.nems.studentrecord.dao.mapper.JournalRenewalOrderRelationshipMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class JournalRenewalOrderRelationshipServiceImpl implements JournalRenewalOrderRelationshipService {
    private final JournalRenewalOrderRelationshipMapper journalRenewalOrderRelationshipMapper ;
    @Override
    public List<JournalRenewalOrderRelationship> findListByRecordId(String recordId) {
        return journalRenewalOrderRelationshipMapper.selectList(
                                new LambdaQueryWrapper<JournalRenewalOrderRelationship>()
                                        .eq(JournalRenewalOrderRelationship::getStudentRecordId,recordId)
                                        .eq(JournalRenewalOrderRelationship::getDeletedFlag ,false)
                                .orderByDesc(JournalRenewalOrderRelationship::getCreatedDatetime)) ;
    }

    @Override
    public JournalRenewalOrderRelationship getByOrderId(String orderId) {
        return journalRenewalOrderRelationshipMapper.selectOne(new LambdaQueryWrapper<JournalRenewalOrderRelationship>()
                .eq(JournalRenewalOrderRelationship::getOrderId, orderId)
                .eq(JournalRenewalOrderRelationship::getDeletedFlag, false));
    }

    @Override
    public List findRecordIdsByRenewalId(String renewalId) {
        return  journalRenewalOrderRelationshipMapper.selectObjs(
                new LambdaQueryWrapper<JournalRenewalOrderRelationship>().select(JournalRenewalOrderRelationship::getStudentRecordId)
                        .eq(JournalRenewalOrderRelationship::getJournalRenewalId, renewalId));
    }
}
